//
//  DeatailViewController.m
//  jishiben
//
//  Created by MM on 2017/12/12.
//  Copyright © 2017年 jishiben. All rights reserved.
//

#import "DeatailViewController.h"
#import "MyDbTools.h"
@interface DeatailViewController ()
@property (nonatomic, strong) UIImageView * bgImageView;

@end

@implementation DeatailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGB(243, 243, 247);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (id)initWithObj:(MoodObj *)obj Image:(UIImage *)image
{
    if ([super init]) {
        self.bgImageView = [[UIImageView alloc] initWithImage: image];
        [self.view addSubview: self.bgImageView];
        self.bgImageView.top = UI_NAVIGATION_BAR_STATUS_BAR_HEIGHT;
        UILabel * labelTime = [[UILabel alloc]initWithFrame: CGRectMake(15.f, self.bgImageView.bottom, ScreenWidth-15.f, 30)];
        [self.view addSubview: labelTime];
        labelTime.text = obj.creatDate;
        labelTime.font = [UIFont systemFontOfSize: 14.f];
        labelTime.textColor = RGB(136, 136, 136);
        
        UIView *_shadowView = [[UIView alloc] initWithFrame: CGRectMake(15, labelTime.bottom, ScreenWidth-30, 70)];
        _shadowView.layer.cornerRadius = 5.f;
        _shadowView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview: _shadowView];
        
        UIImageView *_imageMood = [[UIImageView alloc] initWithFrame: CGRectMake(15, (_shadowView.height-46)/2, 46, 46)];
        _imageMood.layer.cornerRadius = _imageMood.height/2;
        _imageMood.layer.masksToBounds = YES;
        
        UIImageView *_wetherIcon = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"sun_Image"]];
        _wetherIcon.left = _shadowView.width-15-_wetherIcon.width;
        _wetherIcon.top = 15;
        
        UILabel *_labelDate = [[UILabel alloc] initWithFrame: CGRectMake(_shadowView.width-80, 40, 65, 20)];
        _labelDate.font = [UIFont systemFontOfSize: 14.f];
        _labelDate.textAlignment = NSTextAlignmentRight;
        _labelDate.textColor = RGBA(0, 0, 0, 0.6);
        
       UILabel * labelWeek = [[UILabel alloc] initWithFrame: _shadowView.bounds];
        labelWeek.font = [UIFont systemFontOfSize: 18];
        labelWeek.textColor = [UIColor blackColor];
        labelWeek.textAlignment = NSTextAlignmentCenter;
        
        [_shadowView addSubview: _imageMood];
        [_shadowView addSubview: labelWeek];
        [_shadowView addSubview: _wetherIcon];
        [_shadowView addSubview: _labelDate];
        
        
        _labelDate.text = [NSString getDateTimeInterval: obj.creatTime Format: @"HH:mm" isMS: NO];
        
        NSArray * weatherList = [MyDbTools getWeatherList];
        NSArray * moodList = [MyDbTools getMoodList];
        if (obj.mood<moodList.count) {
            _imageMood.image = [UIImage imageNamed: moodList[obj.mood]];
        }
        if (obj.weather<weatherList.count) {
            _wetherIcon.image = [UIImage imageNamed: weatherList[obj.weather]];
        }
        
        labelWeek.text = [labelTime.text weekDayStr: @"yyyy-MM-DD"];
        
        UIScrollView * bgscroll = [[UIScrollView alloc] initWithFrame: CGRectMake(0, _shadowView.bottom+8, ScreenWidth, ScreenHeight-_shadowView.bottom-8)];
        bgscroll.backgroundColor = [UIColor whiteColor];
        [self.view addSubview: bgscroll];
        UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake(3, 0, ScreenWidth-6, 20)];
        [bgscroll addSubview: label];
        label.text = obj.doText;
        label.numberOfLines = 0;
        label.font = [UIFont systemFontOfSize: 16];
        label.textAlignment = NSTextAlignmentCenter;
        NSDictionary * dic =@{NSFontAttributeName:label.font};
        CGSize size = [label.text boundingRectWithSize: CGSizeMake(ScreenWidth, 10000) options: NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes: dic context: nil].size;
        label.height = size.height+40;
        bgscroll.contentSize = CGSizeMake(ScreenWidth, label.bottom);
        
    }
    return self;
}
 - (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = NO;
}
- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;
}
@end
